Merge pull request #5927 from iNavFlight/dzikuvx-programming-refactor
[inav/snaewe.git] / docs / Logic Conditions.md
blob97f24933bb45fb5de754ffe8e2d43de30cabc236
1 # Logic Conditions
3 Logic Conditions (abbr. LC) is a mechanism that allows to evaluate cenrtain flight parameters (RC channels, switches, altitude, distance, timers, other logic conditions) and use the value of evaluated expression in different places of INAV. Currently, the result of LCs can be used in:
5 * [Servo mixer](Mixer.md) to activate/deactivate certain servo mix rulers
6 * [Global functions](Global%20Functions.md) to activate/deactivate system overrides
8 Logic conditions can be edited using INAV Configurator user interface, of via CLI
10 ## CLI
12 `logic <rule> <enabled> <activatorId> <operation> <operand A type> <operand A value> <operand B type> <operand B value> <flags>`
14 * `<rule>` - ID of Logic Condition rule
15 * `<enabled>` - `0` evaluates as disabled, `1` evaluates as enabled
16 * `<activatorId>` - the ID of _LogicCondition_ used to activate this _Condition_. _Logic Condition_ will be evaluated only then Activator evaluates as `true`. `-1` evaluates as `true`
17 * `<operation>` - See `Operations` paragraph
18 * `<operand A type>` - See `Operands` paragraph
19 * `<operand A value>` - See `Operands` paragraph
20 * `<operand B type>` - See `Operands` paragraph
21 * `<operand B value>` - See `Operands` paragraph
22 * `<flags>` - See `Flags` paragraph
24 ### Operations
26 | Operation ID  | Name      | Notes                                 |
27 |----           |----       |----                                   |
28 | 0             | TRUE      | Always evaluates as true              |
29 | 1             | EQUAL     | Evaluates `false` if `false` or `0`   |
30 | 2             | GREATER_THAN  |                                   |
31 | 3             | LOWER_THAN    |                                   |
32 | 4             | LOW           | `true` if `<1333`                 |
33 | 5             | MID           | `true` if `>=1333 and <=1666`     |
34 | 6             | HIGH          | `true` if `>1666`                 |
35 | 7             | AND           |                                   |
36 | 8             | OR            |                                   |
37 | 9             | XOR           |                                   |
38 | 10            | NAND          |                                   |
39 | 11            | NOR           |                                   |
40 | 12            | NOT           |                                   |         
41 | 13            | STICKY        | `Operand A` is activation operator, `Operand B` is deactivation operator. After activation, operator will return `true` until Operand B is evaluated as `true`|         
43 ### Operands
45 | Operand Type  | Name      | Notes                                 |
46 |----           |----       |----                                   |
47 | 0             | VALUE     | Value derived from `value` field      |
48 | 1             | RC_CHANNEL    | `value` points to RC channel number, indexed from 1   |
49 | 2             | FLIGHT        | `value` points to flight parameter table              |
50 | 3             | FLIGHT_MODE   | `value` points to flight modes table                  |
51 | 4             | LC            | `value` points to other logic condition ID            |
53 #### FLIGHT
55 | Operand Value | Name          | Notes                                 |
56 |----           |----           |----                                   |
57 | 0             | ARM_TIMER     | in `seconds`                          |
58 | 1             | HOME_DISTANCE | in `meters`                           |
59 | 2             | TRIP_DISTANCE | in `meters`                           |
60 | 3             | RSSI          |                                       |
61 | 4             | VBAT          | in `Volts * 10`, eg. `12.1V` is `121` |
62 | 5             | CELL_VOLTAGE  | in `Volts * 10`, eg. `12.1V` is `121` |
63 | 6             | CURRENT       | in `Amps * 100`, eg. `9A` is `900`    |
64 | 7             | MAH_DRAWN     | in `mAh`                              |
65 | 8             | GPS_SATS      |                                       |
66 | 9             | GROUD_SPEED   | in `cm/s`                             |
67 | 10            | 3D_SPEED      | in `cm/s`                             |
68 | 11            | AIR_SPEED     | in `cm/s`                             |
69 | 12            | ALTITUDE      | in `cm`                               |
70 | 13            | VERTICAL_SPEED |  in `cm/s`                           |
71 | 14            | TROTTLE_POS   | in `%`                                |
72 | 15            | ATTITUDE_ROLL | in `degrees`                          |
73 | 16            | ATTITUDE_PITCH | in `degrees`                         |
74 | 17            | IS_ARMED              | boolean `0`/`1`               |
75 | 18            | IS_AUTOLAUNCH         | boolean `0`/`1`               |
76 | 19            | IS_ALTITUDE_CONTROL   | boolean `0`/`1`               |
77 | 20            | IS_POSITION_CONTROL   | boolean `0`/`1`               |
78 | 21            | IS_EMERGENCY_LANDING  | boolean `0`/`1`               |
79 | 22            | IS_RTH                | boolean `0`/`1`               |
80 | 23            | IS_WP                 | boolean `0`/`1`               |
81 | 24            | IS_LANDING            | boolean `0`/`1`               |
82 | 25            | IS_FAILSAFE           | boolean `0`/`1`               |
84 #### FLIGHT_MODE
86 | Operand Value | Name          | Notes                                 |
87 |----           |----           |----                                   |
88 | 0             | FAILSAFE      |                                       |
89 | 1             | MANUAL        |                                       |
90 | 2             | RTH           |                                       |
91 | 3             | POSHOLD       |                                       |
92 | 4             | CRUISE        |                                       |
93 | 5             | ALTHOLD       |                                       |
94 | 6             | ANGLE         |                                       |
95 | 7             | HORIZON       |                                       |
96 | 8             | AIR           |                                       |
98     
99 ### Flags
101 All flags are reseted on ARM and DISARM event.
103 | bit   | Decimal   | Function              |
104 |----   |----       |----                   |
105 | 0     | 1         | Latch - after activation LC will stay active until LATCH flag is reseted |